var app = getApp()
Page({

    data: {
        auction_id: '', // 活动id

        goods_list: [], // 商品列表

        delete_id:0,    // 删除id
    },
    deleteGoods: function(id) {
        var self = this
        var goods_list = this.data.goods_list;

        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/auction/del_goods',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        goods_id: id
                    },
                    success: function(res) {
                        var datas = res.data;
                        var list = [];
                        if (res.data.code == 1) {
                            goods_list.map(function (item, index) {
                                if (item.id == id) {
                                    goods_list.splice(index, 1)
                                }
                            })
                            self.setData({goods_list})
                            wx.showToast({
                                title: datas.msg,
                            })
                        }else{
                            wx.showToast({
                                image:"../../img/warning.png",
                                title: datas.msg,
                            })
                        }
                    }
                })
            },
        })
    },
	getGoodsList(){
		var self = this;
        var auction_id = this.data.auction_id;
		wx.getStorage({
			key: 'user',
			success: function (res) {
				wx.request({
					url: app.url.requestUrl + '/auction/auctionlist',
					method: 'POST',
					data: {
						openid: res.data.openid,
						token: res.data.token,
                        auction_id: auction_id
					},
					success: function (res) {
						if (res.data.code == 1) {
							self.setData({
								goods_list: res.data.data.data,
							})
						}
					}
				})
			},
		})
	},
    // 显示删除弹窗
    showDelete(e){
        this.setData({
            delete_id:e.target.dataset.id
        })
        this.dialog.showDialog();
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var self = this;
        this.setData({auction_id: options.id});
        this.dialog = this.selectComponent("#dialog");
    },
    // 删除商品 - 确认
    __confirmDeleteYesEvent(){
        var goods_id = this.data.delete_id;
        this.deleteGoods(goods_id)
        this.dialog.hideDialog();
    },
    // 删除商品 - 取消
    __confirmDeleteNoEvent(){
        this.dialog.hideDialog();
    },
    onShow(){
        this.getGoodsList()
    },
})